package com.ihr360.job.endpoint;

import com.ihr360.job.config.BatchConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

/**
 * @author davidwei
 *         获取任务状态
 */
@Component
public class ThreadPoolStatus {
    final Logger logger = LoggerFactory.getLogger(ThreadPoolStatus.class);

    public PoolStatus getPoolStatus() {
        ThreadPoolTaskExecutor asyncExecutor = BatchConfig.asyncExecutor();
        int corePoolSize = asyncExecutor.getCorePoolSize();
        int activeCount = asyncExecutor.getActiveCount();
        int maxPoolSize = asyncExecutor.getMaxPoolSize();
        int poolSize = asyncExecutor.getPoolSize();
        int keepAliveSeconds = asyncExecutor.getKeepAliveSeconds();
        return new PoolStatus(corePoolSize, maxPoolSize, poolSize, activeCount, keepAliveSeconds);
    }

    public void showPoolStatus() {
        logger.info(getPoolStatus().toString());
    }
}